package com.kongge.viewdisplayframeworklib.landscape;

import android.app.Activity;
import android.content.pm.ActivityInfo;

import com.kongge.viewdisplayframeworklib.util.EQConstans;

/**
 * 屏幕管理类，控制横竖转换的映射关系
 * @author gaoshiqi
 *
 */
public class EQScreenManager {
	

	// ~常量区块
	// ========================================================
	/**
	 * 可横竖屏切换的Frame对应表
	 */
	public static int[][] turnScreenRecord = {
		// 竖屏FrameId，横屏FrameId
		{1001,1002}
	};
	
	// 横竖屏frame在记录中的索引isPortraitFrame
	private static final byte SCREEN_RECORD_INDEX_PORTRAIT = 0;
	private static final byte SCREEN_RECORD_INDEX_LANDSCAPE = 1;

	// ~成员变量区块
	// ========================================================
	// 当前应用的Frameid
	private int mCurPageId = EQConstans.INVALID_ID;
	

	// ~构造函数区块
	// ========================================================

	// ~方法区块
	// ========================================================
	
	// ~静态方法区块
	// ========================================================
	/**
	 * 获取frame对应屏幕方向的pageId
	 * @param curPageId
	 * @param desScreenOrientation
	 * @return
	 */
	public static int getScreenMappingPage(int curPageId, int desScreenOrientation) {
		int mappingPage = EQConstans.INVALID_ID;
		int desIndex = SCREEN_RECORD_INDEX_PORTRAIT;  // 目标 
		int searchIndex = SCREEN_RECORD_INDEX_PORTRAIT; // 查找
		if (desScreenOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {  // 是否具有竖屏
			desIndex = SCREEN_RECORD_INDEX_LANDSCAPE;
			searchIndex = SCREEN_RECORD_INDEX_PORTRAIT;
		} else if (desScreenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { // 是否具有横屏
			desIndex = SCREEN_RECORD_INDEX_PORTRAIT;
			searchIndex = SCREEN_RECORD_INDEX_LANDSCAPE;
		}
		int turnRecordCount = turnScreenRecord.length;
		for (int i = 0; i < turnRecordCount; i++) {
			if (turnScreenRecord[i][desIndex] == curPageId) {
				mappingPage = turnScreenRecord[i][searchIndex];
				break;
			}
		}
		return mappingPage;
	}
	
	public static int getDeviceOrientation(Activity activity) {
		int deviceOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
		if (activity != null) {
			deviceOrientation = activity.getResources().getConfiguration().orientation;
		}
		return deviceOrientation;
	}

	// ~内部接口（类）区块
	// ========================================================

}
